package Thread;

import Chess.BorderPane;
import Chess.Controller;
import Chess.Main;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;

public class TimeThread extends Thread{
	public void run(){
		while(Main.a>0){
			if(Main.stop==1&&chessstartreceiver.data==1){
			Main.a--;	
			}
			try {
				Thread.sleep(1000);
				} catch (InterruptedException e) {
					
				}			
			Main.countdown.setText(Main.a+"");					
			if(Main.a==0){
				if(BorderPane.currentSide=="W"){
					Controller.image = new Image("images/blackPawn.png");
					Controller.images = new ImageView(Controller.image); 					
					BorderPane.currentSide="B";
					Main.a=60;
				}
				else {
					Controller.image =  new Image("images/whitePawn.png");
					Controller.images = new ImageView(Controller.image);					
					BorderPane.currentSide="W";
					Main.a=60;
				}
			}
		}		
	}
}
